package portal.pubimpl.system.pf;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import nc.vo.pub.BusinessException;
import portal.pub.util.pf.JsonObjectUtil;
import portal.pub.util.pf.Result;
import portal.pubitf.system.IUserMapper;
import portal.pubitf.system.pf.IUserService;
import portal.pubvo.system.UserVo;

@Service("userServiceImpl")
public class UserServiceImpl implements IUserService {

	@Autowired
	private IUserMapper userMapper;

	@Override
	public UserVo getById(String id) {
		return userMapper.getById(id);
	}

	@Override
	public List<UserVo> getAll() {
		return userMapper.getAll();
	}

	@Override
	public List<UserVo> getPagesByWhere(String queryWhere) {
		return userMapper.getPagesByWhere(queryWhere);
	}

	@Override
	public Integer getPagesTotalByWhere(String queryWhere) {
		return userMapper.getPagesTotalByWhere(queryWhere);
	}

	@Override
	public int insert(UserVo vo) {
		return userMapper.insert(vo);
	}

	@Override
	public int update(UserVo vo) {
		return userMapper.update(vo);
	}

	@Override
	public String getAllByWhere(String queryWhere) {
		List<UserVo> users = new ArrayList<UserVo>();
		Result result = new Result();
		try {
			users = userMapper.getAllByWhere(queryWhere);
			if(users.size()<=0) {
				throw new BusinessException("手机号不存在");
			}
			result.setUser(users.get(0));
			result.setStatus("0");
			result.setMessage("查询成功");
		} catch (Exception e) {
			result.setStatus("1");
			result.setMessage(e.getMessage());
		}
		return JsonObjectUtil.objectTojson(result);
	}
}
